import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Vant from 'vant'
import 'vant/lib/index.css'
Vue.config.productionTip = false
Vue.use(Vant)
router.beforeEach((to,from,next)=>{
  if (to.meta.requireLogin){
    console.log('需要登陆')
    if (window.localStorage.getItem('user')){
      next()
    } else {
      next('/login')
    }
  }else {
    next()
  }
})
Vue.prototype.getViewPortOffset = ()=>{
  if(window.innerWidth) {
    return {
      w: window.innerWidth,
      h: window.innerHeight
    }
  } else {
    if(document.compatMode === "BackCompat") {
      //compatMode 用来确认是否关闭或开启了标准兼容模式
      //BackCompat：标准兼容模式关闭。
      //CSS1Compat：标准兼容模式开启。
      return {
        w: document.body.clientWidth,
        h: document.body.clientHeight
      }
    } else {
      return {
        w: document.documentElement.clientWidth,
        y: document.documentElement.clientHeight
      }
    }
  }
}
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
